// 电影列表
import { request } from "../utils/request.js";

export default {
    // 列表的页数
    get: ({ curPage, eachPage }) => request({
        // GET获取数据
        type: "GET",
        url: "/api/movies",
        data: { curPage, eachPage },
    }),
    // 以Restful风格规范 格式
    // 拿到id
    getOne: _id => request({
        // GET获取数据
        type: "GET",
        url: `/api/movies/getone/${_id}`,

    }),
    //需要新增的后台请求
    add: student => {
        return request({
            //POST 在服务器新增一个资源
            type: "post",
            url: "/api/movies/add-movies",
            data: student,
        })
    },

    // 点击删除按钮
    delete: _id => request({
        type: "DELETE",
        url: `/api/movies/${_id}`,
    }),

    // 修改电影信息
    revise: ({ cname, ename, type, area, time, upDate, score, count, intro, isClassic, director, actor, _id })=> request({
        type: "PATCH",
        url: `/api/movies/${_id}`,
        data: { cname, ename, type, area, time, upDate, score, count, intro, isClassic, director, actor, _id },
    }),

    // 删除图片
    deleteImg: ({ _id, url }) => request({
        //DELETE 删除数据
        type: "DELETE",
        // 获取动态的路径
        url: `/resource/movies/${_id}/movies/${encodeURIComponent(url)} `,
    }),
    // 查询
    find: ({ type,isClassic }) => request({
        type: "GET",
        url: `/api/movies/find`,
        data:{ type,isClassic },
    }),
    // 删除海报
    deletePoster:({ _id, url }) => request({
        //DELETE 删除数据
        type: "DELETE",
        // 获取动态的路径
        url: `/resource/movies/${_id}/moviesPoster/${encodeURIComponent(url)} `,
        // url: `/resource/moviesPoster/${_id}/poster/${encodeURIComponent(url)} `,

    }),

    //会话间 cookie:传统的存储方式（会自动保存到请求头 以键值对的方式）  localStorage setStorage H5新增的方法 以JSON格式的字符串存在
    // 让localStorage["movies"]=JSON.stringify 针对(movies)
    setStorage: (movies) => localStorage["movies"] = JSON.stringify(movies),
    getStorage: () => JSON.parse(localStorage["movies"]), // 拿到localStorage["movies"]通过parse字符串转JSON


}